package com.freeter.service;

import com.freeter.dao.SysGeneratorDao;
import com.freeter.entity.ColumnEntity;
import com.freeter.entity.TableEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 作者  freeter E-mail:
 * @version 1.0
 * @date 创建时间：2018年7月9日 上午10:30:15
 * @parameter
 * @return 获取mysql数据库信息
 * @since
 */


@Service("mysqlDataBaseService")
public class MysqlDataBaseService extends DataBaseInfo {

    @Autowired
    private SysGeneratorDao sysGeneratorDao;


    @Override
    public String queryDatabaseName() {
        return sysGeneratorDao.queryDatabaseName();
    }

    @Override
    public List<TableEntity> getTableList() {
        List<TableEntity> tables = sysGeneratorDao.queryTableList(null);

        tables.stream().forEach((tableInfo) -> {
            List<ColumnEntity> columns = sysGeneratorDao.selectAllColumns(tableInfo.getTableName());
            tableInfo.setColumns(columns);
        });
        return tables;
    }


}
